/**
 * @desc
 * @author  刘贺[of2220]
 * @company qianmi.com
 * @Date    2017/2/9
 */
import React from 'react';
import {msg} from 'iflux';
import {Button, Icon,Upload,message} from 'antd';
const prefix = 'http://qianmi-web.oss-cn-hangzhou.aliyuncs.com/';
export default class OperationButton extends React.Component {
    render() {
        const props = {
            name: 'file',
            action: '/relatedImgInfo/imgUpload',

            onChange(info) {
                if (info.file.status !== 'uploading') {
                    console.log(info.file, info.fileList);
                }
                if (info.file.status === 'done') {
                    let url = info.file.response.url;
                    let {name,size:fileSize} = info.file;
                    let img = new Image();
                    img.src = prefix + url;
                    img.onload = function(){
                        let imgSize = `${img.width},${img.height}`;
                        //图片数据入库
                        msg.emit('save::image',{name,src:url,fileSize,imgSize});
                    };
                } else if (info.file.status === 'error') {
                    message.error(`${info.file.name} file upload failed.`);
                }
            },
        };
        return (<div>
            <Upload showUploadList={false} accept="image/*" {... props}>
                <Button style={{marginRight: '10px'}}>
                    <Icon type="upload"/>上传图片
                </Button>
            </Upload>
            <Button onClick={()=>{msg.emit('create::new::cate')}}>
                <Icon type="folder"/>新建文件夹
            </Button>
        </div> )
    }
}